<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(target, nums) {
      let res; //返回值
      let i = 0, j = 0; //双指针
      let sum = 0;
      for (; j < nums.length; j++) {
        sum += nums[j];
        while (sum >= target) {
          res = res < j - i + 1 ? res : j - i + 1;
          sum -= nums[i];
          i++;
        }
      }
      return res ? res : 0;
    };
    console.log(arr(target = 7, nums = [2, 3, 1, 2, 4, 3]));
  </script>
</body>

</html>